<template>
  <div class="layout-container logging-contain">
    <PageHeader title="日志管理">
      <template #btns>
        <div class="search common-buttons">
          <!-- <div class="span1">
            <span>时间</span>
          </div>
          <div>
            <el-date-picker 
              v-model="formtable.timevalue" 
              type="datetimerange" 
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              format="YYYY-MM-DD hh:mm:ss"
              value-format="YYYY-MM-DD hh:mm:ss"
              style="width: 300px;"
              clearable
            />
          </div> -->
          <div class="span1">
            <span>用户</span>
          </div>
          <el-input v-model.trim="formtable.username" placeholder="请输入" clearable />
          <!-- <el-select v-model.trim="formtable.username" :loading="usernameloading" filterable remote :remote-method="getusernameOptions" placeholder="请输入" clearable>
            <el-option 
              v-for="item in usernameOptions"
              :key="item"
              :label="item"
              :value="item">
            </el-option>
          </el-select> -->
          <div class="span1">
            <span>具体操作</span>
          </div>
          <el-input v-model.trim="formtable.detail_operation" placeholder="请输入" clearable />
          <!-- <el-select v-model.trim="formtable.detail_operation" :loading="operationloading" filterable remote :remote-method="getoperationOptions" placeholder="请输入" clearable>
            <el-option 
              v-for="item in operationOptions"
              :key="item"
              :label="item"
              :value="item">
            </el-option>
          </el-select> -->
          <div class="common-buttons">
            <el-button type="info" :icon="Search" @click="onQuery({ pageNo: 1 })">搜索</el-button>
            <el-button type="info" @click="onReset">重置</el-button>
          </div>

        </div>
      </template>
      <template #search>
      </template>
    </PageHeader>
        
    <!-- 表格 -->
    <div class="layout-container-table">
      <CommonTable 
        :showSelection=false
        v-loading="loading" 
        v-model:page="page"
        :total="total"
        :data="state.tableData"
        @onQuery="onQuery"
        :header-cell-style="{'text-align':'center'}" 
        :cell-style="{'text-align':'center'}" 
        style="width: 100%">
        <el-table-column prop="operTime" label="操作时间"  />
        <el-table-column prop="loginName" label="用户"  />
        <el-table-column prop="operIp" label="IP地址" />
        <el-table-column prop="detailInfo" label="具体操作"  />
      </CommonTable>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, reactive } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import { getloggingSearch } from '@/api/system/logging'
import store from '@/store'
import PageHeader from '@/components/page-header/index.vue';
import CommonTable from '@/components/common-table/index.vue';
import {
  Plus,
  Delete,
  Download,
  Promotion,
  Search,
  Setting
} from '@element-plus/icons-vue';
import { Page } from '@/components/common-table/type';
//,GetusernameOptionBykeywords,GetoperationOptionBykeywords getloggingData, 
const state = reactive<any>({
  tableData: [],
});
const page = reactive<Page>({
  current: 1,
  pageSize: 20,
});
const total = ref<number>(0);
const loading = ref(false);
//表单
const formtable = reactive({
  timevalue: "",
  username: "",
  detail_operation: "",
});

onMounted(() => {
  onQuery({ pageNo: 1 });
});
const onReset = () => {
  formtable.timevalue='';
  formtable.username='';
  formtable.detail_operation='';
  onQuery({ pageNo: 1 });
};

//表单条件搜索  
const onQuery = async(val: any) =>{
  let params = {
    pageNo:page.current,
    pageSize:page.pageSize,
    startTime:formtable.timevalue[0]?formtable.timevalue[0]:null,
    endTime:formtable.timevalue[1]?formtable.timevalue[1]:null,
    userName:formtable.username?formtable.username:null,
    detailInfo:formtable.detail_operation?formtable.detail_operation:null,
    ...val,
  }
  loading.value = true;
  let result = await getloggingSearch(params);
  loading.value = false;
  total.value=result.data.totalRows;
  state.tableData=result.data.rows;
};

//模糊搜索 数据库表不同另写函数
// const usernameOptions = ref([]);
// const usernameloading = ref(false);
// const getusernameOptions = async(query:any) =>{
//   if (query!=''){
//     let params = {
//       username:query
//     }
//     usernameloading.value = true;
//     let result = await GetusernameOptionBykeywords(params);
//     usernameloading.value = false;
//     usernameOptions.value = result.data.usernameOptions;
//   }else{
//     usernameOptions.value = [];
//   }
  
// }

// const operationOptions = ref([]);
// const operationloading = ref(false);
// const getoperationOptions = async(query:any) =>{
//   if (query!=''){
//     let params = {
//       operation:query
//     }
//     operationloading.value = true;
//     let result = await GetoperationOptionBykeywords(params);
//     operationloading.value = false;
//     operationOptions.value = result.data.operationOptions;
//   }else{
//     operationOptions.value = [];
//   }
  
// }
</script>
<style  lang="scss" scoped>
@import '@/assets/style/buttons';
.logging-contain {
  .search {
    display: flex;
    :deep() {
      .el-input--small .el-input__wrapper {
        margin-right: 10px;
      }
    }
  }

  .layout-container-table {
    .el-button--small {
      background: transparent;
      color: rgba(24, 81, 237, 1);
    }
  }

  .search .span1{
    display: inline-block;
    width: 80px;
    margin: auto;
    font-size:14px;
    text-align: center;
  }
  .search .el-input{
    width: 200px;
    margin: auto;
  }
  .search .el-button {
    background: rgb(1, 18, 90);
    border: 0;
  }

  .btns .el-button {
    background: rgb(1, 18, 90);
    border: 0;
  }
  :deep() {
    .el-dialog__body {
      padding: 10px 20px;
    }
  }
  .el-form-item .el-select {
  width: 100%;
  }


}
.el-input--suffix{
  width: 180px;
}

</style>